<template>
  <div class="dashboard-container">
    <div style="padding: 20px">
      <el-table
        ref="multipleTable"
        v-loading="listLoading"
        :data="list"
        height="calc(100vh - 180px)"
        style="width: 100%;"
        size="mini"
        border
        tooltip-effect="dark"
        :header-cell-style="{ background: '#eaf1fd', color: '#333' }"
      >
        <el-table-column
          label="文件名"
          prop="task_name"
          width="200px"
        />

        <el-table-column
          label="状态"
          width="200px"
        >
          <template slot-scope="{ row }">
            <div>
              <span v-if="row.status == 1" style="color:green">已完成</span>
              <span v-if="row.status == 0" style="color:#1890ff">未完成</span>
            </div>
          </template>

        </el-table-column>
        <el-table-column
          label="创建时间"
          prop="created_at"
        />
        <el-table-column
          label="操作"
          align="right"
          width="150"
          class-name="small-padding fixed-width"
          fixed="right"
        >
          <template slot-scope="{ row }">
            <el-button
              v-if="row.status == 1"
              size="mini"
              type="primary"
              @click="cheackIsDown(row)"
            >
              下载
            </el-button>
          </template>
        </el-table-column>
      </el-table>
      <pagination
        v-show="total>0"
        :total="total"
        :page.sync="listQuery.page"
        :limit.sync="listQuery.limit"
        @pagination="getList"
      />
    </div>
  </div>
</template>

<script>
import { mapGetters } from 'vuex'
import { DownList } from '@/api/dashboard/dashboard'
import Pagination from '@/components/Pagination' // secondary package based on el-pagination

export default {
  name: 'Dashboard',
  components: {
    Pagination
  },
  data() {
    return {
      tableKey: 0,
      list: null,
      total: 0,
      listLoading: true,
      listQuery: {
        page: 1,
        limit: 20
      }
    }
  },
  computed: {
    ...mapGetters([
      'roles'
    ])
  },
  created() {
    this.getList()
  },
  methods: {
    cheackIsDown(row) {
      const a = document.createElement('a')
      a.style.display = 'none'
      // 下载连接
      a.href = 'http://promise.yunda.kr' + row.url
      a.download = '下载文件'
      // 文件名称
      document.body.appendChild(a)
      a.click()
      // 移除元素
      document.body.removeChild(a)
      // 释放
      window.URL.revokeObjectURL(a.href)
    },
    getList() {
      this.listLoading = true
      DownList(this.listQuery).then(response => {
        this.list = response.data.data
        this.total = response.data.total
        this.listLoading = false
      })
    }
  }
}
</script>
<style scoped>
.filter-container{
  padding:20px 20px 10px;
}

.upload-demo{
  margin: 20px 0 10px;
}
</style>
